package com.smart.seckilldemo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.seckilldemo.commons.result.ResponseResult;
import com.smart.seckilldemo.commons.result.ResultCodeEnum;
import com.smart.seckilldemo.pojo.Good;
import com.smart.seckilldemo.pojo.User;
import com.smart.seckilldemo.commons.vo.GoodsVo;
import com.smart.seckilldemo.service.GoodsService;
import com.smart.seckilldemo.utils.CurrentUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 商品列表 详情查询
 */
@Slf4j
@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    GoodsService goodsService;
    @Resource
    CurrentUtils currentUtils;


    /**
     * 跳转到商品列表页
     * @param
     * @param

     * @return
     */
    @GetMapping(value = "/toList")
    @ResponseBody
    public ResponseResult toList(@RequestParam(value = "current",defaultValue = "1") Long current,HttpServletRequest request){
        if(currentUtils.current(request)){
            return ResponseResult.success(goodsService.findGoodList(current));
        }else {
            return ResponseResult.error(ResultCodeEnum.INTERFACE_BUSY_ERROR);
        }

    }

    /**
     * 跳转商品详情页
     * @return
     */
    @RequestMapping(value = "/toDetail/{goodsId}")
    @ResponseBody
    public ResponseResult toDetail(@PathVariable("goodsId") Long goodsId){
        return ResponseResult.success(goodsService.findGoodByGoodId(goodsId));
    }



}
